package com.cykj.service.impl;

import com.cykj.mapper.ScenicMapper;
import com.cykj.pojo.Scenic;
import com.cykj.pojo.User;
import com.cykj.service.ScenicService;
import com.cykj.util.PageResult;
import com.cykj.util.PageUtils;
import com.cykj.util.ResponseDto;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScenicServiceImpl implements ScenicService {
    @Autowired
    private ScenicMapper scenicMapper;
    @Override
    public ResponseDto delete(int id) {
        scenicMapper.delete(id);
        return new ResponseDto(1,"删除成功",null);
    }

    @Override
    public ResponseDto alter(int id, String name, String price, String address, String info) {
        int alter = scenicMapper.alter(id, name, price, address, info);
        return new ResponseDto(1,"修改成功",null);
    }

    @Override
    public ResponseDto countTicketForScenic() {
        List<Integer> count = new ArrayList<>();
        String [] arr = new String[]{"清源山", "泉州开元寺","木偶戏剧表演","西街","崇武古城风景区","欧乐堡海洋王国","清境桃源","石牛山景区","五店市传统街区","洛阳桥","泉州府文庙","泉州南少林寺","泉州安平桥","泉州草庵摩尼教寺"};
        for (String item : arr) {
            int i = scenicMapper.countTicketForScenic(item);
            count.add(i);
        }
        return new ResponseDto(1,"查询成功",count);
    }

    @Override
    public ResponseDto addScenic(String name, String price, String address, String info) {
        int i = scenicMapper.addScenic(name, price, address, info);
        return new ResponseDto(1,"添加成功",null);
    }

    @Override
    public ResponseDto searchInfo(int pageCurr, int pageSize, String value) {
        Page<Object> page = PageHelper.startPage(pageCurr, pageSize);
        List<Scenic> ticketsOrders = scenicMapper.searchInfo(value);
        PageInfo<Object> pageInfo = new PageInfo<>(page);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return new ResponseDto(1,"查询成功",pageResult);
    }
}
